/*
  Copyright 2007 Anders Båtstrand

      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.

 */

package org.dyndns.anderlin.jmplayer.model;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

@Entity
public class Performance extends JmplayerObject {

    @ManyToOne
    @JoinColumn(nullable = false)
    private Artist performer;

    @ManyToOne
    @JoinColumn(nullable = false)
    private Instrument instrument;

    @ManyToOne
    @JoinColumn(nullable = false)
    private Track recording;


    public Artist getPerformer() {
        return performer;
    }

    public void setPerformer(Artist performer) {
        this.performer = performer;
    }

    public Instrument getInstrument() {
        return instrument;
    }

    public void setInstrument(Instrument instrument) {
        this.instrument = instrument;
    }

    public Track getRecording() {
        return recording;
    }

    public void setRecording(Track recording) {
        this.recording = recording;
    }

    public String toString() {
        return performer + " playing " + instrument + " on " + recording;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Performance that = (Performance) o;

        if (ID != null ? !ID.equals(that.ID) : that.ID != null) return false;
        if (instrument != null ? !instrument.equals(that.instrument) : that.instrument != null) return false;
        if (performer != null ? !performer.equals(that.performer) : that.performer != null) return false;
        if (recording != null ? !recording.equals(that.recording) : that.recording != null) return false;

        return true;
    }

    public int hashCode() {
        int result;
        result = (ID != null ? ID.hashCode() : 0);
        result = 31 * result + (performer != null ? performer.hashCode() : 0);
        result = 31 * result + (instrument != null ? instrument.hashCode() : 0);
        result = 31 * result + (recording != null ? recording.hashCode() : 0);
        return result;
    }
}